<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html >
<html lang="en">
<head>
<%@include file="../../common/includeBaseSet.jsp" %>
<%@include file="../../common/includeSystemSet.jsp" %>
<%@include file="../../common/operation_forbid.jsp" %>
<%@include file="../../common/jsVersion.jsp" %>
</head>
<body>
	<div class="page-content">
		    <div class="col-xs-12 panel panel-success" style="height:200px;width:97%;margin-left:7px"> 
	         	<div class="col-xs-6" style="width:100%">
				     <div class="form-group" style="margin-top:10px">
						<label class="col-xs-2 control-label" style="width:100px">选择文件:</label>
						<input type="text" id="textName" style="width:265px;" placeholder="上传附件" readOnly/> 
	                    <img style="width:30px;cursor:pointer" onclick="callImport('file','textName')" src="${jypath}/resources/images/upload_a.png"/>
	                    <input type="file" style="display:none" onchange="ajaxfile('file')" id="file" name="file"/>
				     </div>
				     <div class="form-group" style="margin-top:10px;text-align:center;">
						<button type="button" onclick="upload('file')" class="btn btn-default">导入</button>
				     </div>
				     <div id="msg" class="form-group" style="margin-top:10px;border-top:1px solid #d9d9d9;">
						<!-- 导入信息 -->
				     </div>
				 </div>
		    </div>
	</div>	
</body>
<script type="text/javascript">
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	
	//导入，触发file点击事件
	function callImport(fileId, textId){ 
	  	var a=document.createEvent("MouseEvents");
	  	a.initEvent("click", true, true);  
	  	document.getElementById(fileId).dispatchEvent(a); 
	} 
	function ajaxfile(fileId){
	  	$("#textName").val($("#"+fileId).val());
	}
	//excel
	function upload(fileId){
		layer.load(0, {shade: false}); //弹出加载层
		$.ajaxFileUpload ({
			url:'${jypath}/deal/areaRepair/uploadExcel',
			secureuri:false,
			fileElementId:fileId,
			dataType: 'json',
			success: function (data, status) {
				layer.closeAll('loading'); //关闭加载层
				console.log(data);
				if(data.res == "1"){
					var obj = data.obj;
					
					if(obj.successCount > 0){
						layer.msg("导入成功");
					}else{
						layer.msg("导入失败");
					}
					
					var text = "共"+obj.total+"条<br/>";
						text += "导入成功"+obj.successCount+"条<br/>";
						text += "导入失败"+obj.failCount+"条<br/>";
					if(obj.failCount > 0){
						//text += "<a>导出错误数据</a>";
						expFail();
					}
					$("#msg").html(text);
					
					//刷新父窗口列表
					parent.getCount();
					//parent.getbaseList(1);
				}else{
					layer.msg(data.resMsg);
				}
			}
		});

		$("#textName").val("");
	}
	
	function expFail(){
		location.href = jypath+'/deal/areaRepair/expFail';
	}
</script>
</html>